package com.chapter1;

import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname Equivalence
 * @Description 测试对象的等价性
 * @Date 2019/4/27 17:18
 * @Created by xiangty
 */
public class Equivalence {

    public static void main(String[] args){
//        strEquMethod();
//        shortCircuit();

        duiBi();
    }

    /**
     * 与（||）和 按位与（|）对比
     */
    public static void duiBi(){
        List<String> lists = new ArrayList<>();
        if(CollectionUtils.isEmpty(lists)){
            System.out.println("空集合");
        }

        if(lists == null || lists.size() == 0){
            System.out.println("与，输出集合为空");
        }

        try {
            // 按位与，会把所有的条件都执行，直到所有的都执行完成。
            if (lists == null | lists.size() == 0) {
                System.out.println("按位与，输出集合为空");
            }
        } catch (Exception e){
            e.printStackTrace();
            System.out.println("出现异常");
        }
    }

    /**
     * 输出逻辑运算符的demo
     */
    public static void shortCircuit(){
        System.out.println((1<2) && (1>3));
        System.out.println((1<2) && (1<3));
        System.out.println((1<2) || (1>3));
        System.out.println((1<2) || (1<3));
        System.out.println(1 != 2);
    }

    /**
     * 字符串的Equals方法的输出demo
     */
    public static void strEquMethod(){
        String str1 = "a";
        String str2 = "a";
        String str3 = new String("a");
        String str4 = new String("a");

        System.out.println("str1==str2    " + (str1==str2));
        System.out.println("str1==str3    " + (str1==str3));
        System.out.println("str3==str4    " + (str3==str4));
        System.out.println("str1.equals(str3)    " + (str1.equals(str3)));

        str3 = str3.intern();
        System.out.println("str1==str3    " + (str1==str3));

        /*
            str1==str2    true
            str1==str3    false
            str3==str4    false
            str1.equals(str3)    true
            str1==str3    true
         */
    }

}
